package cn.zhibang.yygh2.service.user.controller.api;

import cn.zhibang.yygh2.common.util.result.Result;
import cn.zhibang.yygh2.common.util.util.IpUtil;
import cn.zhibang.yygh2.model.vo.user.LoginVo;
import cn.zhibang.yygh2.service.user.service.UserInfoService;
import com.alibaba.nacos.client.utils.IPUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/api/usr")
public class UserInfoApiController {
    @Resource
    private UserInfoService userInfoService;


    @ApiOperation(value = "会员登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo, HttpServletRequest request){
        loginVo.setIp(IpUtil.getIpAddr(request));

        Map<String,Object> info = userInfoService.login(loginVo);

        return Result.ok(info);
    }
}

